<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label=" 漫画id" prop="comicId">
        <el-select v-model="queryParams.comicId" clearable filterable placeholder="请选择">
          <el-option
            v-for="item in options1"
            :key="item.comicId"
            :label="item.comicName"
            :value="item.comicId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="章节" prop="comicChapterDirectory">
        <el-input
          v-model="queryParams.comicChapterDirectory"
          placeholder="请输入章节"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="章节名" prop="comicChapterName">
        <el-input
          v-model="queryParams.comicChapterName"
          placeholder="请输入章节名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['xqsp:comicChapter:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['xqsp:comicChapter:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['xqsp:comicChapter:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['xqsp:comicChapter:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="comicChapterList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="章节编号" align="center" prop="comicChapterId" />
      <el-table-column label=" 漫画id" align="center" prop="comicId" />
      <el-table-column label="章节" align="center" prop="comicChapterDirectory" />
      <el-table-column label="章节名" align="center" prop="comicChapterName" />
      <el-table-column label="章节内容" align="center" :show-overflow-tooltip="true" prop="comicChapterImg" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['xqsp:comicChapter:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xqsp:comicChapter:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改漫画章节对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label=" 漫画" prop="comicId">
          <el-select v-model="form.comicId" clearable filterable placeholder="请选择">
            <el-option
              v-for="item in options1"
              :key="item.comicId"
              :label="item.comicName"
              :value="item.comicId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="章节" prop="comicChapterDirectory">
          <el-input v-model="form.comicChapterDirectory" placeholder="请输入章节" />
        </el-form-item>
        <el-form-item label="章节名" prop="comicChapterName">
          <el-input v-model="form.comicChapterName" placeholder="请输入章节名" />
        </el-form-item>
        <el-form-item label="章节内容" prop="comicChapterImg1">
          <el-input v-model="form.comicChapterImg" @blur="addImg" placeholder="请输入章节图片" />
        </el-form-item>
        <div><span style="font-size: 18px;color: red" >特别注意：多图拼接最后不能以“,”结尾!!!</span></div>
        <el-form-item label="多图拼接" prop="comicChapterImg2">
          <el-input :disabled=this.test1  v-model="form.comicChapterImg2"  type="textarea" autosize placeholder="多图拼接(特别注意：多图拼接最后不能以“,”结尾)" />
          <el-button type="info" size="mini" @click="test">修改</el-button>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComicChapter, getComicChapter, delComicChapter, addComicChapter, updateComicChapter, exportComicChapter } from "@/api/xqsp/comicChapter";
import { listComic} from "@/api/xqsp/comic";
export default {
  name: "ComicChapter",
  components: {
  },
  data() {
    return {
     // 漫画下拉框
      options1:[],
      // 遮罩层
      loading: true,
      test1:true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 漫画章节表格数据
      comicChapterList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        comicId: null,
        comicChapterDirectory: null,
        comicChapterName: null,
        comicChapterImg: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getComicList();
  },
  methods: {


    /** 查询漫画操作列表 */
    getComicList() {
      this.loading = true;
      listComic(this.queryParams).then(response => {
        this.options1 = response.rows;
      });
    },

    /** 查询漫画章节列表 */
    getList() {
      this.loading = true;
      listComicChapter(this.queryParams).then(response => {
        this.comicChapterList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    test(){

      if (this.test1==true){
        this.test1=false;
      }else {
        this.test1=true;
      }


    },
    // 表单重置
    reset() {
      this.form = {
        comicChapterId: null,
        comicId: null,
        comicChapterDirectory: null,
        comicChapterName: null,
        comicChapterImg: null,
        comicChapterImg2: null,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.comicChapterId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    addImg(){

      if (this.form.comicChapterImg2!=null){
        this.form.comicChapterImg2 = this.form.comicChapterImg+","+this.form.comicChapterImg2;
      }else {
        this.form.comicChapterImg2 = this.form.comicChapterImg
      }

      this.form.comicChapterImg="";
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加漫画章节";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const comicChapterId = row.comicChapterId || this.ids
      getComicChapter(comicChapterId).then(response => {
        this.form = response.data;
        this.$set(this.form,'comicChapterImg2',response.data.comicChapterImg)
        this.form.comicChapterImg="";
        this.open = true;
        this.title = "修改漫画章节";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.comicChapterId != null) {
            this.form.comicChapterImg=this.form.comicChapterImg2;
            updateComicChapter(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.comicChapterImg=this.form.comicChapterImg2;
            addComicChapter(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const comicChapterIds = row.comicChapterId || this.ids;
      this.$confirm('是否确认删除漫画章节编号为"' + comicChapterIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delComicChapter(comicChapterIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有漫画章节数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportComicChapter(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
<style ang="scss">
  .el-tooltip__popper{
    max-width: 300px;
    font-size: 16px;
    background: #000 !important;/*背景色  !important优先级*/
    opacity: 0.8 !important;/*背景色透明度*/
    color: #FFFFFF !important;/*字体颜色*/
  }
</style>

